<template>
  <div id="root">
    <es-router-view ></es-router-view>
  </div>
</template>

<script lang="ts">
import {defineComponent} from '@vue/runtime-core';
import {
  ESLogLevel,
  useES,
  useESDevelop,
  useESDevice,
  useESDisplay,
  useESLog,
  useESRuntime,
  useESToast
} from "@extscreen/es3-core";
import {
  ESPlayerConfiguration,
  ESPlayerDisplay,
  ESPlayerLogLevel,
  useESPlayer,
  useESPlayerLog
} from "@extscreen/es3-player";
import { useRequestManager} from "./api/UseApi";
import {useLaunch} from "./tools/launch/useApi";
import {useESNativeRouter, useESRouter} from "@extscreen/es3-router";
import BuildConfig from "./build/BuildConfig";
export default defineComponent({
  name: 'App',
  components:{
  },
  setup() {
    //
    const log = useESLog()
    const es = useES()
    const develop = useESDevelop()
    const device = useESDevice()
    const runtime = useESRuntime()

    const playerManager = useESPlayer()
    const router = useESRouter()
    const nativeRouter = useESNativeRouter()
    const request = useRequestManager()
    const launch = useLaunch()
    const playerLog = useESPlayerLog()
    const toast = useESToast()
    function onESCreate(app, params) {
      console.log("--1-应用----app-------onESCreate---->>>>>", params)
      initESLog()
      return Promise.resolve()
        .then(() => request.init(es, develop, device, runtime, log))
        .then(() => launch.init(log, router, nativeRouter,develop,toast))
        .then(() => playerManager.init({
          debug: false,
          display: {
            screenWidth: device.getScreenWidth(),
            screenHeight: device.getScreenHeight(),
          },
          device: {
            deviceType: runtime.getRuntimeDeviceType() ?? ''
          }
        }))
    }

    function onESCreated(success) {
      console.log("---应用---app-------onESCreated---->>>>>", success)
    }

    function onESStart() {
      console.log("---应用---app-------onESStart---->>>>>")
    }

    function onESNewIntent(intent) {
      console.log("---应用---app-------onESNewIntent---->>>>>", intent)
    }

    function onESRestart() {
      console.log("---应用---app-------onESRestart---->>>>>")
    }

    function onESResume() {
      console.log("---应用---app-------onESResume---->>>>>")
    }

    function onESPause() {
      console.log("---应用---app-------onESPause---->>>>>")
    }

    function onESStop() {
      console.log("---应用---app-------onESStop---->>>>>")
    }

    function onESDestroy() {
      console.log("---应用---app-------onESDestroy---->>>>>")
    }
    function initESLog() {
      if (BuildConfig.debug) {
        log.setMinimumLoggingLevel(ESLogLevel.DEBUG)
        playerLog.setMinimumLoggingLevel(ESPlayerLogLevel.DEBUG)
      } else {
        log.setMinimumLoggingLevel(ESLogLevel.WARN)
        playerLog.setMinimumLoggingLevel(ESPlayerLogLevel.WARN)
      }
    }
    return {
      onESCreate,
      onESCreated,
      onESStart,
      onESNewIntent,
      onESRestart,
      onESResume,
      onESPause,
      onESStop,
      onESDestroy,
    };
  },
});

</script>

<style scoped>
#root {
  width: 1920px;
  height: 1080px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

</style>
